package com.csproj.example.repository.impl;

import com.csproj.example.domain.Organization;
import com.csproj.example.repository.custom.OrganizationRepositoryCustom;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.HashMap;
import java.util.Map;

/**
 * Spring Data JPA repository for the ClassInfo entity.
 */
@SuppressWarnings("unused")
public class OrganizationRepositoryImpl implements OrganizationRepositoryCustom {
	@PersistenceContext
    private EntityManager em;

	public EntityManager getEm() {
		return em;
	}

	/**
	 * 机构分页查询方法
	 * @param map	参数
	 * @param pageable		分页对象
	 * @return
	 */
    public Page<Organization> findPageList(Map<String, Object> map, Pageable pageable) {
        //拼hql
        String hql = " from Organization org where org.delFlag = 0 ";
        String name = (String) map.get("name");
        Map<String,Object> queryParams = new HashMap<>();
        if (StringUtils.isNotBlank(name)) {
            hql += " and org.name like :name";
            queryParams.put("name","%"+name+"%");
        }
        //查询
        Page<Organization> fieldList = query(hql, pageable, queryParams);
        //返回
        return fieldList;
    }

}
